import { createStore } from 'vuex'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    list: [], // 心愿列表
  },
  getters: {
  },
  mutations: {
    saveList(state,val){ // 存储心愿列表
      let obj = {
        ...val,
        time: new Date().toLocaleDateString()
      }
      state.list.push(obj);
    },
    del(state,i){ // 单个删除
      state.list.splice(i,1);
    },
    delectAll(state,arr) { // 批量删除
      state.list = state.list.filter(item => !arr.some(n => n.name == item.name))
      // state.list = state.list.filter(item => arr.includes())
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
      storage: window.localStorage,
    }),
  ]
})
